﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sms_Template_Add.aspx.cs" Inherits="JKF.Web.SMS.Templeate.Sms_Template_Add" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title><%= RegScript("~/js/jquery.1.5.js")%>
    <%=RegScript("~/js/Common.js")%>
    <%=RegScript("~/js/jquery.json.js")%>
    <%=RegScript("~/js/jquery.nhis.js")%>
    <%=RegScript("~/js/jquery.rchis.js")%>
    <%=RegScript("~/js/jquery.validate.js")%>
    <%=RegScript("~/js/DatePicker/WdatePicker.js")%>
    <%= RegScript("~/js/jquery-ui-custom.min.js")%>
    <%=RegScript("~/js/Uppop/tipswindown2.js") %>
    <%=RegStyle("~/js/suggest/jquery.suggest.css")%>
    <%=this.RegStyle("~/App_Themes/Theme2/Include.css")%>
    <script type="text/javascript">
        var appPath = "<%=AppPath %>";
        var isAdd = "<%=NoAddRedirect%>";
        var intSetTimeOutID;
        var handler = appPath + '/do/SMS/SmsModule.do';
        var templateInfo = <%=templateInfo%>;
        var tmpl = new DTemplate();
        $(function () {
            BindValidate();
            $("#btnAdd").click(saveSmsTemplateInfo);
            if (templateInfo) BindData();
        });

        function BindValidate() {
            alxVr.push({
                id: "TEMPLATE_NAME",
                rule: function (cn) {
                    var actVal = $.trim(cn.val());
                    if (actVal.length == 0) {
                        this.msg = "请输入模版名称.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "IS_START",
                rule: function (cn) {
                    var actVal = $.trim(cn.val());
                    if (actVal == "") {
                        this.msg = "请选择是否启用.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "IS_SHARE",
                rule: function (cn) {
                    var actVal = $.trim(cn.val());
                    if (actVal == "") {
                        this.msg = "请选择是否共享.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "CONTENT",
                rule: function (cn) {
                    var actVal = $.trim(cn.val());
                    if (actVal == "") {
                        this.msg = "请输入模版内容.";
                        return false;
                    }
                    if (actVal.length > 50) {
                        this.msg = "模版内容不可超过50个字符.";
                        return false;
                    }
                    return true;
                }
            });
            $.validateBind();
            $("#InsertFields").change(function() {
                var vl = $.trim($(this).val());
                if(vl.length>0) $("#CONTENT").val($("#CONTENT").val()+$.FxNull($(this).val(),""));
            });
        }

        function saveSmsTemplateInfo() {
            if (!$.validateAll()) {
                if ($(".alxv-failed").size() > 0) {
                    $(document).scrollTop($(".alxv-failed").eq(0).scrollTop());
                }
                return;
            };
            var obj = {
                ID:(templateInfo==null || templateInfo==undefined)?"":$.FxNull(templateInfo.ID,""),
                TEMPLEATE_NAME:$.trim($("#TEMPLATE_NAME").val()),
                IS_START:$.trim($("#IS_START").val()),
                IS_SHARE:$.trim($("#IS_SHARE").val()),
                CONTENT:$.trim($("#CONTENT").val())
            };

            $.post(handler, { ActionName: "EditSmsTemplate", smsTemplate: $.toJSON(obj)}, function (data) {
                if (data.Success) {
                    top.popRetuInfo(data.Data);
                    if ((templateInfo == null || templateInfo == undefined))
                        $.popResultTip('操作成功', [["clearForm()", "继续添加"], ["top.tipsWindown.close()", "返回列表"]]);
                    else
                        $.popResultTip('操作成功', [["top.tipsWindown.close()", "返回列表"]]);
                    return;
                }
                alert(data.Message);
            }, "json");
        }

        function clearForm() {
            $(":text").val("");
            $("select").val("");
            $("textarea").val("");
            try {
                $('#resultTipDiv').dialog('close');    
                clearTimeout(intSetTimeOutID);
            } catch(e) {
            } 
        }

        function BindData() {
            var obj = templateInfo;
            $("#TEMPLATE_NAME").val($.FxNull(obj.TEMPLEATE_NAME,""));
            $("#IS_START").val($.FxNull(obj.STATUS,""));
            $("#IS_SHARE").val($.FxNull(obj.IS_SHARE,""));
            $("#CONTENT").val($.FxNull(obj.CONTENT,""));
        }
    </script>
</head>
<body style="height: auto;">
    <form id="form1" runat="server">
        <div class="pop_logging_body">
            <table width="100%" class="common_table_noborde">
                <tr>
                    <td width="18%" align="right"><span class="f12red">*</span>模版名称：
                    </td>
                    <td>
                        <input id="TEMPLATE_NAME" type="text" class="common_search_input w150" />
                    </td>
                    <td width="18%" align="right">
                        <span class="f12red">*</span>是否启用
                    </td>
                    <td>
                        <select id="IS_START" class="common_search_select w150">
                            <option value="">请选择</option>
                            <option value="1">启用</option>
                            <option value="0">停用</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td width="18%" align="right">
                        <span class="f12red">*</span>是否共享：
                    </td>
                    <td>
                        <select class="common_search_select w150" id="IS_SHARE">
                            <option value="">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </td>
                    <td width="18%" align="right">插入字段：
                    </td>
                    <td>
                        <select id="InsertFields" class="common_search_select w150">
                            <option value="">请选择</option>
                            <option value="{顾客卡号}">顾客卡号</option>
                            <option value="{姓名}">姓名</option>
                            <option value="{性别}">性别</option>
                            <option value="{生日}">生日</option>
                           <%-- <option value="{剩余积分}">剩余积分</option>
                            <option value="{发送店面名称}">发送店面名称</option>
                            <option value="{发送店面电话}">发送店面电话</option>--%>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td width="18%" align="right" valign="top"><span class="f12red">*</span>模版内容：</td>
                    <td colspan="3">
                        <textarea id="CONTENT" rows="5" class="w450"></textarea>
                    </td>
                </tr>
            </table>
            <div class="pop_btn">
                <input id="btnAdd" type="button" value="" class="common_btn_save mr30 mb25" />
                <input id="btnClose" type="button" value="" class="common_btn_remove mb25" onclick="top.tipsWindown.close();" />
            </div>
        </div>
    </form>
</body>
</html>
